package com.situ.mall.test;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class User implements BeanNameAware, BeanFactoryAware, ApplicationContextAware, InitializingBean, DisposableBean {

    public User() {
        System.out.println("User的构造方法执行了.........");
    }

    private String name ;

    @Value("张三")
    public void setName(String name) {
        System.out.println("User.setName name="+name);
    }

    //实现BeanNameAware接口
    @Override
    public void setBeanName(String name) {
        System.out.println("User.setBeanName name="+name);
    }

    //实现BeanFactoryAware接口
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("User.setBeanFactory");
    }

    //实现ApplicationContextAware接口
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("User.setApplicationContext");
    }

    //指定init-method
    @PostConstruct
    public void init() {
        System.out.println("User.init");
    }

    //实现InitializingBean接口
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("User.afterPropertiesSet");
    }

    //指定destroy-method
    @PreDestroy
    public void destory() {
        System.out.println("User.destory");
    }

    //实现DisposableBean接口
    @Override
    public void destroy() throws Exception {
        System.out.println("User.destroy");
    }
}
